package week4.onClass.exer01;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        System.out.println(partition(arr, 0, n - 1, k));
    }

    private static int partition(int[] arr, int left, int right, int k) {
        if (left == right) {
            return arr[left];
        }
        int pivot = arr[right];
        int prev = left - 1;
        int cur = left;
        while (cur <= right) {
            if (arr[cur] <= pivot) {
                int tmp = arr[prev + 1];
                arr[prev + 1] = arr[cur];
                arr[cur] = tmp;
                cur++;
                prev++;
            } else {
                cur++;
            }
        }
        int leftCount = prev - left;
        if (leftCount == (k - 1)) {
            return arr[prev];
        } else if (leftCount >= k) {
            return partition(arr, left, prev - 1, k);
        } else {
            return partition(arr, prev + 1, right, (k - leftCount - 1));
        }
    }
}
